package api

import (
	"gitee.com/gcom/stockdock/core/job"
	"gitee.com/gcom/stockdock/core/router"
	s "gitee.com/gcom/stockdock/core/support"
	"gitee.com/gcom/stockdock/spider/ths"
	"net/http"
)

func init() {
	router.ApiRouter.HandleFunc("/industry/list", getIndustryList).Methods("GET")
	router.AdminRouter.HandleFunc("/industry/updateAll", updateIndustryList).Methods("GET")
	router.AdminRouter.HandleFunc("/industry/updateStocks", updateIndustryStocks).Methods("GET")
}

func getIndustryList(w http.ResponseWriter, r *http.Request) {
	ctx := s.GetTracerCtx(w, r)
	li, err := ths.GetIndustryList(ctx.DB)
	if err != nil {
		s.ResError(ctx, 500, err)
		return
	}
	s.ResOk(ctx, li)
}

func updateIndustryList(w http.ResponseWriter, r *http.Request) {
	ctx := s.GetTracerCtx(w, r)
	job.JobThsIndustry.Run(ctx)
}

func updateIndustryStocks(w http.ResponseWriter, r *http.Request) {
	ctx := s.GetTracerCtx(w, r)
	job.JobThsIndustryStock.Run(ctx)
}
